<?php
//清空Blog前台项目的缓存
function clearBlogCache()
{
	import("ORG.Io.Dir");
    Dir::del(BLOG_PATH."/Temp/");
}

//返回插件的启用与禁用状态
function getStatus($status,$imageShow=true) 
{
    switch($status) {
    	case 0:
            $showText   = "禁用";
            $showImg    = '<IMG SRC="'.WEB_PUBLIC_URL.'/Images/locked.gif" width="20" height="20" border="0" alt="禁用">';
            break;
        case 1:
        default:
            $showText   =   "正常";
            $showImg    =   '<img src="'.WEB_PUBLIC_URL.'/Images/ok.gif" width="20" height="20" border="0" alt="启用">';
            
    }
    return ($imageShow===true)? auto_charset($showImg) : $showText;
}

//改变插件状态
function changePlugInStatus($id,$status)
{
	switch($status) {
    	case 0:
            return "<a href=\"".url('changeStatus','PlugIn','',APP_NAME,array('id'=>$id,'status'=>'1'))."\">启用插件</a>";
        case 1:
        default:
            return "<a href=\"".url('changeStatus','PlugIn','',APP_NAME,array('id'=>$id,'status'=>'0'))."\">禁用插件</a>";
    }
}

//显示友情链接打开的窗口对象
function parseTarget($target)
{
	if($target == "_blank")
		return "新窗口";
	else if($target == "_self")
		return "本窗口";
}

//显示用户个人资料中的头像
function parseFaceImg($picture)
{
	if(empty($picture))
		return WEB_PUBLIC_URL."/Images/noface.gif";
	else
		return $picture;
}

//读取模板目录下的readme.txt文件显示模板相关信息
function getTemplateDesrc($template)
{
	$content = file_get_contents(BLOG_PATH."/Tpl/".$template."/readme.txt");
	return str_replace(array("\r","\n","'"),array("","<br />","\\'"),$content);
}

//把中文用google翻译变成英文
function translateByGoogle($post_title)
{
	import("@.ORG.Snoopy");

	$post_title = str_replace(
		array('[转载]','zz','`','~','!','@','#','$','%','^','&','*','(',')','-','_','+','=',
		'|','\\','\'','"',';',':','/','?','.','>',',','<','[','{',']','}','·','～','！','＠',
		'＃','￥','％','……','＆','×','（','）','－','——','＝','＋','＼','｜','【','｛','】',
		'｝','‘','“','”','；','：','、','？','。','》','，','《',' ','　'), "",$post_title);

	$fp = new Snoopy();
	$fp->agent = 'Mozilla/5.0 (Windows; U; Windows NT 5.1; zh-CN; rv:1.9.1.1) Gecko/20090715 Firefox/3.5.1 (.NET CLR 3.5.30729)';
	$fp->accept = 'Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8';
	$fp->referer = 'http://translate.google.cn/translate_t?prev=hp&hl=zh-CN&js=y&text=%E7%8B%97&file=&sl=zh-CN&tl=en&history_state0=';
	$fp->fetch('http://translate.google.cn/translate_a/t?client=t&text='.urlencode($post_title).'&sl=zh-CN&tl=en');
	$result = $fp->results;

	if (preg_match('/^\\["(.*?)",.*\\]$/', $result, $regs)) {
		$result = $regs[1];
	}

	return str_replace(array('"',' '),array('','_'),$result);
}
?>